<template>
	<div class="comment">
		<CommentList :commentlistData="commentlistData" :commentPageTotal="commentPageTotal" :commentPageNum="commentPageNum" @getMoreComments="getMoreComments" :count="commentListCount" :newsId="newsId" />
		<DownloadAppButton :newsTitle="newsTitle" :newsId="newsId" :newsDate="newsDate" />
	</div>
</template>

<script>
	import CommentList from "../../components/comment/comment-list.vue";
	import DownloadAppButton from "../../components/download-app/download-app-button.vue";
	export default {
		name: "Comment",
		props:["newsTitle", "newsDate"],
		data:function(){
			return {
				commentlistData:[],
				commentListCount:0,
				newsId:null,
				commentPageNum: 1,
				commentPageTotal: 0
			}
		},
		methods:{
			getMoreComments: function(n) {
				this.$set(this, "commentPageNum", n || 1);
				let that = this;
				let newsId = this.$route.params.id;
				that.$set(that, "newsId", newsId);
				this.$http.jsonp(this.$store.state.api.commentListApi.tmpl({
					newsId: newsId,
					pgnum: n || 1
				})).then(function(res){
					//console.log(res)
					let data =that.commentlistData||[];
					res.body.revdata.articledata && res.body.revdata.articledata.each((i, item) => {
						data.push({
							id: item.id,
							logo: item.logo,
							content: item.content,
							time: dateFormat(item.posttime),
							userid: item.userid,
							username: item.username,
							praisecount: item.praisecount,
							parentid: item.parentid,
							parentuserid: item.parentuserid,
							parentusername: item.parentusername,
							ispraise: item.ispraise
						})
					});
					//console.log(data)
					that.$set(that, "commentlistData", data);
					that.$set(that, "commentListCount", res.body.revdata.articledata && res.body.revdata.articledata.length || 0);
					that.$set(that, "commentPageTotal", res.body.revdata.pagesize);
				}, function(){
					
				})
			}
		},
		created: function(){
			let that = this;
			that.getMoreComments(that.commentPageNum);
		},
		components:{
			CommentList,
			DownloadAppButton
		}
	}
</script>

<style lang="less">
	@base:23.44/1rem;
	.comment{
		
	}
</style>
